home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / jav503.zip / IMAGEAP.JAV < prev    next >
Text File  |  1996-05-30  |  2KB  |  107 lines

  1. // -[KeepHeading]-
  2.  
  3.  
  4. // -[Copyright]-
  5.  
  6. /**
  7.  * (c) Step Ahead Software Pty Ltd 1996. All rights reserved. Registered
  8.  * users may use this applet in their web pages.
  9.  */
  10. import java.lang.*;
  11.  
  12.  
  13. // -[KeepBeforeClass]-
  14. import java.awt.Rectangle;
  15. import java.awt.Color;
  16. import java.awt.Graphics;
  17. import java.awt.Font;
  18. import java.awt.FontMetrics;
  19. import    java.awt.Image;
  20. import java.applet.Applet;
  21.  
  22.  
  23. // -[Class]-
  24.  
  25. /**
  26.  * @jTitle           ImageApplet
  27.  * @jAuthor          Chris Colman
  28.  * @jOverridability  can be overridden
  29.  * @jDescription
  30.  * ImageApplet is a JAVA applet that demonstrates how to display an image
  31.  * on the screen.
  32.  * 
  33.  * @see              Applet
  34.  */
  35. public 
  36. class ImageApplet extends Applet
  37. {
  38. // -[KeepWithinClass]-
  39.  
  40.  
  41. // -[Fields]-
  42.  
  43.  
  44.  
  45. /**
  46.  * Image object.
  47.  */
  48. protected Image image;
  49.  
  50.  
  51.  
  52. /**
  53.  * A string object containing the JAVelin text with a message.
  54.  */
  55. protected String javString= "Javelin (tm) - Reach for the sky!";
  56.  
  57.  
  58.  
  59. /**
  60.  * Font used for central message.
  61.  */
  62. protected Font largeFont= new Font("TimesRoman",Font.BOLD,24);
  63.  
  64.  
  65.  
  66. // -[Methods]-
  67.  
  68. /**
  69.  * Initializes the applet.
  70.  */
  71. public void init()
  72. {
  73.     resize(400, 400);
  74.     image = getImage(getDocumentBase(), "backg.gif");
  75. }
  76.  
  77.  
  78.  
  79.  
  80. /**
  81.  * Called whenever a window needs updating.
  82.  */
  83. public void paint(Graphics g)
  84. {
  85.     Rectangle r = bounds();
  86.  
  87.     g.drawImage(image, 0, 0, r.width, r.height, this);
  88.  
  89.     // Remember current font so that we can restore things back
  90.     // to the way they were when finished
  91.     Font oldFont = g.getFont();
  92.     Color oldColor = g.getColor();
  93.  
  94.     g.setColor(Color.red);
  95.  
  96.     g.setFont(largeFont);
  97.     FontMetrics fm = g.getFontMetrics();
  98.     
  99.     g.drawString(javString,
  100.                                          (r.width - fm.stringWidth(javString))/2,
  101.                                          (r.height - fm.getHeight())/2);
  102.  
  103.     g.setFont(oldFont);
  104.     g.setColor(oldColor);
  105. }
  106. }
  107.